package com.da.javatest.leetCode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author chenlida
 * @date 2019/1/14 16:09
 * @description
 */
public class Code100 {
    private List<Integer> l1 = new ArrayList<>();
    private List<Integer> l2 = new ArrayList<>();

    public boolean isSameTree(TreeNode p, TreeNode q) {
        setList(p, l1);
        setList(q, l2);
        System.out.println(l1);
        System.out.println(l2);
        if (l1.size() != l2.size()) {
            return false;
        }
        for (int i = 0; i < l1.size(); i++) {
            if (!l1.get(i).equals(l2.get(i))) {
                return false;
            }
        }
        return true;
    }

    private void setList(TreeNode node, List<Integer> l) {
        if (node != null) {
            l.add(node.val);
            if (node.left == null && node.right != null) {
                l.add(-1);
            }
            setList(node.left, l);
            setList(node.right, l);
        }
    }
}
